In [18]:
import pymongo
import sympy
from sympy.parsing.sympy_parser import parse_expr
import os
In [3]:
# Maybe you have to change mongo url to something else if you're non the DAQ network? See cax.config.
client = pymongo.MongoClient('mongodb://eb:%s@xenon1t-daq.lngs.infn.it:27017/run' % os.environ['MONGO_PASSWORD'])
In [14]:
purity_coll = client['run']['purity']
purity_coll.count()
Out[14]:
In [15]:
d = purity_coll.find_one()
In [17]:
for d in purity_coll.find(sort=(('calculation_time', -1), )):
print(str(d['calculation_time']), parse_expr(d['function']))
In [21]:
import numpy as np
In [132]:
data = np.array([
4, 0.9948, # Julien
5, 1.1224, # Julien
6, 1.2137, # Julien
7, 1.2833, # Julien
8, 1.3323, # Julien
9, 1.371, # Jelle
12, 1.4401, # Jelle & Julien (same value, well Julien had 1.4402 and I had 1.440...)
13, 1.456,
15, 1.482
])
cathode_kv, vdrift_kmpers = data.reshape(-1, 2).T
In [133]:
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline
In [149]:
vs = np.linspace(0, 20, 100)
deg = len(cathode_kv) - 4
coeffs = np.polyfit(cathode_kv, vdrift_kmpers, deg=deg)
plt.plot(vs, np.polyval(coeffs, vs), label='%dth degree polynomial fit' % deg)
plt.scatter(cathode_kv, vdrift_kmpers, marker='x', c='k', label='Datapoints')
plt.ylim(0.5, 1.7)
plt.legend(loc='lower right')
plt.xlabel("Cathode voltage (kV)")
plt.ylabel("Drift velocity (km/sec)")
Out[149]:
In [150]:
plt.plot(cathode_kv, 100 * (np.polyval(coeffs, cathode_kv) - vdrift_kmpers)/vdrift_kmpers,
linestyle='', marker='x')
plt.ylabel('Relative fit error (%)')
plt.xlabel("Cathode voltage kV")
Out[150]:
Systematic error on drift velocity estimates is around 0.2%, see : https://xecluster.lngs.infn.it/dokuwiki/doku.php?id=xenon:xenon1t:aalbers:drift_and_diffusion#results
so if the fitter error is much less than this, we're ok.
In [153]:
v = sympy.Symbol('v')
sp_poly = sympy.Poly.from_list(coeffs.tolist(), gens=v)
In [155]:
# Sanity check:
sp_poly.subs(dict(v=7.5))
Out[155]:
In [166]:
# Try converting to and from serialization format, repeat sanity check
serialized_fit = sympy.srepr(sp_poly)
parse_expr(serialized_fit).subs(dict(v=7.5))
Out[166]:
In [167]:
drift_coll = client['run']['drift_velocity']
In [173]:
from datetime import datetime
In [172]:
# Uncomment this, adjust versions and comments to do actual insertion
# drift_coll.insert_one(dict(
# version='1.0.0',
# calculation_time=datetime.now(),
# function=serialized_fit,
# comment="5th degree polynomial fit to Julien&Jelle's Drift velocity results. Jelle, 1 April 2017."
# ))
Out[172]: